<!doctype html>
<html lang="en">
	<head>
		<title>Tween.js / complex properties</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div id="info">
			<h1><a href="http://github.com/tweenjs/tween.js">tween.js</a></h1>
			<h2>15 _ complex properties</h2>
			<p>Simple example for illustrating animation of nested properties.</p>
		</div>
		<div
			id="target"
			style="
				position: absolute;
				transform: translate(100px, 100px);
				width: 100px;
				height: 100px;
				background: #a0dde9;
				padding: 1em;
			"
		>
			hello world!
		</div>

		<script type="module">
			import * as TWEEN from '../dist/tween.esm.js'

			const group = new TWEEN.Group()

			const position = {x: 100, y: 100, styles: {opacity: 1.0}}
			const target = document.getElementById('target')
			const tween = new TWEEN.Tween(position, group)
				.to({x: 700, y: 200, styles: {opacity: 0}}, 1000)
				.delay(1000)
				.onUpdate(update)

			const tweenBack = new TWEEN.Tween(position, group)
				.to({x: 100, y: 100, styles: {opacity: 1.0}}, 1000)

				.onUpdate(update)

			tween.chain(tweenBack)
			tweenBack.chain(tween)

			tween.start()

			animate()

			function animate(time) {
				group.update(time)
				requestAnimationFrame(animate)
			}

			function update(values) {
				target.style.opacity = values.styles.opacity
				target.style.transform = `translate(${values.x}px, ${values.y}px)`
			}
		</script>
	</body>
</html>
